<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core">

<ui:composition template="/common/template.xhtml">
	
	<ui:define name="pageContent">
	
		<h:form>
			<h:panelGroup>
			<table class="mainTable">
			<tr>
			<td>
				<h:outputLabel value="Име на доставчик">
					<h:selectOneMenu value="#{pregledNaPriemaneNa4asti.searchSupplier}">
						<f:selectItems value="#{pregledNaPriemaneNa4asti.suppliers}" var="currSupplier"
							itemLabel="#{currSupplier.name}" itemValue="#{currSupplier.ID}" />
					</h:selectOneMenu>
				</h:outputLabel>
				</td>
				<td>
				<h:outputLabel value="Статус">
					<h:selectOneMenu value="#{pregledNaPriemaneNa4asti.searchStatus}">
						<f:selectItems value="#{pregledNaPriemaneNa4asti.statuses}" var="currSstatus"/>
					</h:selectOneMenu>
				</h:outputLabel>
				</td>
				</tr>
				<tr>
				<td>
				<h:outputLabel value="Дата на доставката(от)">
					<h:inputText id="dateFrom" value="#{pregledNaPriemaneNa4asti.searchDateFrom}"
						convertorMessage="Невалидна дата. Пример: 21.12.2012" >
						<f:convertDateTime pattern="dd.MM.yyyy" />
					</h:inputText>
				</h:outputLabel>
				</td>
				<td>
				<h:outputLabel value="Дата на доставката(до)">
					<h:inputText id="dateTo" value="#{pregledNaPriemaneNa4asti.searchDateFrom}"
						convertorMessage="Невалидна дата. Пример: 21.12.2012" >
						<f:convertDateTime pattern="dd.MM.yyyy" />
					</h:inputText>
				</h:outputLabel>
				</td>
				</tr>
				<tr>
				<td>
				<h:commandButton value="Търси" class="regButton" action="#{pregledNaPriemaneNa4asti.searchIt()}"
					style="width:80px;height:40px;margin-top:20px;margin-left:20px;" />
				<h:commandButton value="Изчисти" class="regButton"  action="#{pregledNaPriemaneNa4asti.searchIt()}"
					style="width:80px;height:40px;"/>
				</td>
				</tr>
				</table>
			</h:panelGroup>
		</h:form>
		
	    <h:form>

	    
		<div id="scroolTable"> <!-- scroll bar -->
		<!-- за Калин - избрания ред ще има клас = "selectedRow", неизбраните = "notSelectedRow" -->
		<h:dataTable
			rows="#{configurationProperties.getPageSize()}"
			value="#{pregledNaPriemaneNa4asti.spisukDostavki}"
			var="curr"
			first="0"
			rowClasses="#{pregledNaPriemaneNa4asti.rowStyleClasses}">
			
			<f:facet name="header">
			Доставки
			</f:facet>
			
			<h:column>
				<f:facet name="header">Номер на придружаващ документ</f:facet>
				<h:outputText value="#{curr.documentNumber}" />
			</h:column>
			
			<h:column>
				<f:facet name="header">Дата на придружаващ документ</f:facet>
				<h:outputText value="#{curr.documentDate}" />
			</h:column>
			
			<h:column>
				<f:facet name="header">Дата на придружаващ документ</f:facet>
				<h:outputText value="#{curr.documentDate}" />
			</h:column>
			
			<h:column>
				<f:facet name="header">Дата на доставката</f:facet>
				<h:outputText value="#{curr.documentDate}" />
			</h:column>
			
			<h:column>
				<f:facet name="header">Статус на доставката</f:facet>
				<h:outputText value="#{curr.status == '1' ? 'Неплатена' : 'Платена'}" />
			</h:column>
			
			<h:column>
				<f:facet name="header">Номер на платежно нареждане</f:facet>
				<h:outputText value="#{curr.paymentNumber}" />
			</h:column>
			
			<h:column>
				<f:facet name="header">Обща сума</f:facet>
				<h:outputText value="#{curr.fullPrice}" />
			</h:column>
			
			<h:column>
				<f:facet name="header">Промени</f:facet>
				<h:commandButton action="#{pregledNaPriemaneNa4asti.chooseDelivery(curr)}" value="Промени" class="inTableButton"/>
			</h:column>
			
			<f:facet name="footer">
				
				<!-- предишна страница -->
				<h:commandLink disabled="#{pregledNaPriemaneNa4asti.page - 1 lt 0}"
					action="#{pregledNaPriemaneNa4asti.setPage(pregledNaPriemaneNa4asti.page - 1)}"
					value="&lt;&lt;" />
					
				<h:outputText value=" " />
					
				<!-- други страници -->
				<ui:repeat value="#{pregledNaPriemaneNa4asti.pagesList}" var="currPage">
					<h:commandLink
						disabled="#{pregledNaPriemaneNa4asti.getPage() eq currPage.intValue() - 1}"
						action="#{pregledNaPriemaneNa4asti.setPage(currPage.intValue() - 1)}"
						value="#{currPage}" />
						
					<h:outputText value=" " />
				</ui:repeat>
				
				<!-- следваща страница -->
				<h:commandLink disabled="#{pregledNaPriemaneNa4asti.page + 1 ge pregledNaPriemaneNa4asti.pagesCount}"
					action="#{pregledNaPriemaneNa4asti.setPage(pregledNaPriemaneNa4asti.page + 1)}"
					value="&gt;&gt;" />
						
			</f:facet>
			
		</h:dataTable>
		</div>
		<br />
		<table class="mainTable" style="margin-bottom:10px;">
		<tr>
		<td>
		<h:outputLabel value="Номер на придружаващ документ"><br />
	    	<h:inputText id="documentNumber" value="#{pregledNaPriemaneNa4asti.documentNumber}" 
	    		readonly="true" />
	    	<h:message for="documentNumber" class="errorMsg" />
	    </h:outputLabel>
	    </td>
	    <td>
	    <h:outputLabel value="Дата на придружаващ документ"><br />
	    	<h:inputText id="documentDate" value="#{pregledNaPriemaneNa4asti.documentDate}" 
	    		readonly="true">
	    		<f:convertDateTime pattern="dd.MM.yyyy" />
	    	</h:inputText>
	    	<h:message for="documentDate" class="errorMsg" />
	    </h:outputLabel>
	    </td>
	    <td>
	    <h:outputLabel value="Дата на доставката"><br />
	    	<h:inputText id="deliveryDate" value="#{pregledNaPriemaneNa4asti.deliveryDate}" 
	    		readonly="true">
	    		<f:convertDateTime pattern="dd.MM.yyyy" />
	    	</h:inputText>
	    	<h:message for="deliveryDate" class="errorMsg" />
	    </h:outputLabel>
	    </td>
	    </tr>
	    <tr>
	    <td>
	    <h:outputLabel value="Статус*" style="width:242px;height:40px;">
			<h:selectOneMenu value="#{pregledNaPriemaneNa4asti.status}"
				readonly="#{(pregledNaPriemaneNa4asti.status eq 'Платена') or (!pregledNaPriemaneNa4asti.rowSelected)}">
				<f:selectItems value="#{pregledNaPriemaneNa4asti.statuses}" />
			</h:selectOneMenu>
		</h:outputLabel>
		</td>
		<td>
		
		<h:outputLabel value="Номер на платежно нареждане"><br />
	    	<h:inputText id="paymentNumber" value="#{pregledNaPriemaneNa4asti.paymentNumber}"
	    		readonly="#{(pregledNaPriemaneNa4asti.status eq 'Платена') or (!pregledNaPriemaneNa4asti.rowSelected)}" />
	    	<h:message for="paymentNumber" class="errorMsg" />
	    </h:outputLabel>
	    </td>
		<td>
		<h:outputLabel value="Обща цена"><br />
	    	<h:inputText id="fullPrice" value="#{pregledNaPriemaneNa4asti.fullPrice}" 
	    		readonly="true" />
	    	<h:message for="fullPrice" class="errorMsg" />
	    </h:outputLabel>
	    </td>
	    </tr>
	    <tr>
		<td>
		<h:commandButton value="Запиши" 
		class="regButton" style="width:80px;height:40px;margin-left:20px;margin-top:20px;"
		action="#{pregledNaPriemaneNa4asti.writeIt()}"
	   		disabled="#{(pregledNaPriemaneNa4asti.status eq 'Платена') or !pregledNaPriemaneNa4asti.rowSelected or !pregledNaPriemaneNa4asti.changingAllowed}" />
	   		
	   	<h:commandButton action="#{pregledNaPriemaneNa4asti.deselectRow()}" value="Отмени"
	   	class="regButton" style="width:80px;height:40px;"
			disabled="#{!pregledNaPriemaneNa4asti.rowSelected}" />
			 
	    
	    <h:outputText value="#{pregledNaPriemaneNa4asti.errorMessage}"/>
	    </td>
	    </tr>
	    </table>
	    
		<div id="scroolTable"> <!-- scroll bar -->
		
		<h:dataTable
			value="#{pregledNaPriemaneNa4asti.spisuk4asti}"
			var="curr"
			rowClasses="notSelectedRow">
			<f:facet name="header">
		Доставени резервни части
		</f:facet>
			<h:column>
				<f:facet name="header">Група</f:facet>
				#{curr.sparePart.sparePartGroup.description}
			</h:column>
			
			<h:column>
				<f:facet name="header">Наименование</f:facet>
				#{curr.sparePart.name}
			</h:column>
			
			<h:column>
				<f:facet name="header">Мерна единица</f:facet>
				#{curr.sparePart.measuringUnit}
			</h:column>
			
			<h:column>
				<f:facet name="header">Доставено</f:facet>
				#{curr.quantity}
			</h:column>
			
			<h:column>
				<f:facet name="header">Цена</f:facet>
				#{curr.price}
			</h:column>
			
			<h:column>
				<f:facet name="header">Общо</f:facet>
				#{curr.quantity * curr.price}
			</h:column>
			
			</h:dataTable>
		</div>
		<br />
		
	    </h:form>
	</ui:define>
	
</ui:composition>
</html>